
package domain;

import java.util.Iterator;
import java.util.Vector;

/**
 *
 * @author shaigi
 */
public class Game {

    public static  Vector<Agent> getAgents() {
        return _agents;
    }
    
    public static enum  direction { RIGHT, LEFT, UP, DOWN };
    public static Board     _board;
    public static final int STEP_COST   = 1;
    public static final int FLAG_COST   = 100;
    public static final int NO_FLAG     = 0;
    public static final int DELAY       = 1500;
    
    //private Board         _board;
    private static Vector<Agent>   _agents;//TODO: Changed to Static (by ika) see if it is good
    private int             _stepsTMP   = 30;  //TODO del
    
    
    public Game(Board board) {
        
        Game._board     = board;
        this._agents    = new Vector<Agent>();
        //initialize();
        
        System.out.println("Game created");
    }
    
    public void start(){
        //@TODO complete code here
        
        //making automatic move on the entire Board
        while (!endOfGame()){
            try {
                Thread.sleep(DELAY);
            } catch (InterruptedException ex) {
                System.out.println("cant sleep");
            }
            for (Iterator<Agent> it = _agents.iterator(); it.hasNext();) {
                Agent agent = it.next();
                agent.play();
                try {
                    Thread.sleep(DELAY);
                } catch (InterruptedException ex) {}
            }
        }
    }

    public void initialize() {
        Agent moshe = new AgentDumbAuto("moshe", direction.RIGHT);
        addAgent(moshe);
        
        Agent smith = new AgentGreedy("smith", direction.RIGHT);
        addAgent(smith);
        
        //TODO add more agents here
    }
    public void placeAgents(){
        _agents.elementAt(0).placeAgent(_board.getSquare(2, 4));
        _agents.elementAt(1).placeAgent(_board.getSquare(6, 5));
    }
    
    public int getNumberOfAgents(){
        return _agents.size();
    }

    private void addAgent(Agent newAgent) {
        _agents.addElement(newAgent);
        //TODO update GUI
    }

    private boolean endOfGame() {
        if (this._stepsTMP > 0){
            this._stepsTMP--;
            return false;
        }
        else
            return true;
    }
    
}
